#coding=utf-8
import os
class callPrompt:
    def __init__(self):
        self.packages=''
    def import_pkg(self,path:str):
        if self.packages:
            self.packages+=('; '+'source {}'.format(path))
        else:
            self.packages=('source {} '.format(path))
    def call(self,functionname,*args):
        cmd=''
        if self.packages:
            cmd+=self.packages
            cmd+=';'
        cmd+=("{}".format(functionname))
        for i in args:
            cmd+=" {}".format(i)
        cmd+=';echo $?'
        # child = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
        # print(cmd)
        val=os.popen(cmd)
        return val.read()
        # print(val.read())
        
ACp=callPrompt();
ACp.import_pkg('./shextern.sh') #加入外部包
val=ACp.call('getsum',1,2,3,4) #调用函数
# val=ACp.call("ls")
print([val])
print([ACp.call("ifconfig")])
# val=os.popen('ls -a').read()
# print(val)

# import subprocess
# val=os.system("ls -al")
# child = subprocess.Popen(['ls','-l'],stdout=subprocess.PIPE)
# print(child.stdout.read())
# print(val.__dict__)